# -*- coding: utf-8 -*-
# @Time : 2024/2/26 13:56
# @Author : ZH
# @File : 56.py
# @Software: PyCharm
class Solution(object):
    def merge(self, intervals):
        """
        :type intervals: List[List[int]]
        :rtype: List[List[int]]
        """
        end_data = sorted(intervals, key=lambda x: x[0])
        rwa = []
        num_min = end_data[0][0]
        num_max = end_data[0][1]
        for i in end_data[1:]:
            if num_max >= i[0]:
                num_max = i[1] if num_max < i[1] else num_max
                continue
            elif num_max < i[0]:
                rwa.append([num_min, num_max])
                num_min = i[0]
                num_max = i[1]
        rwa.append([num_min, num_max])
        return rwa


if __name__ == '__main__':
    so = Solution()
    so.merge([[1,3],[2,6],[8,10],[15,18]])

